package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.ExhibitionInfo;
import com.zjhd.sealcutting.domain.WorksInfo;
import com.zjhd.sealcutting.param.ExhibitionSearchQuery;
import com.zjhd.sealcutting.param.WorksInfoSearchQuery;
import com.zjhd.sealcutting.service.WorksInfoService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.SearchResult;
import com.zjhd.sealcutting.vo.WorksInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * TODO  作品管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/12/1 17:19
 */
@Api(value = "作品管理", tags = "作品管理")
@RequestMapping("/worksInfo")
@RestController
public class WorksInfoController {

    private final static Logger logger = LoggerFactory.getLogger(WorksInfoController.class);

    @Autowired
    private WorksInfoService worksInfoService;

    @ApiOperation(value = "分页查询作品列表接口", notes = "分页查询作品列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workStatus", value = "作品状态 (0 已上传  1:已投稿  2:已入围)", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "workType", value = "作品类型(0:初稿  1：终稿)", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "keyWord", value = "关键字", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryWorksInfoParamlist")
    public ResponseResult<SearchResult<WorksInfoVo>> queryWorksInfoParamlist(WorksInfoSearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.queryWorksInfoParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询作品列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询作品列表接口失败");
        }
    }

    @ApiOperation(value = "新增作品", notes = "新增作品接口")
    @PostMapping("/insertWorksInfo")
    @OperLog(operModul = "作品管理-新增作品",operType = "新增",operDesc = "新增作品")
    public ResponseResult insertWorksInfo(@RequestBody WorksInfoVo worksInfoVo){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.insertWorksInfo(worksInfoVo));
        }catch (Exception ex) {
            logger.error("新增作品接口失败", ex);
            return ResultGenerator.genFailResult("新增作品接口失败");
        }
    }

    @ApiOperation(value = "修改作品", notes = "修改作品接口")
    @PostMapping("/updateWorksInfo")
    @OperLog(operModul = "作品管理-修改作品",operType = "修改",operDesc = "修改作品")
    public ResponseResult updateWorksInfo(@RequestBody WorksInfoVo worksInfoVo){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.updateWorksInfo(worksInfoVo));
        }catch (Exception ex) {
            logger.error("修改作品接口失败", ex);
            return ResultGenerator.genFailResult("修改作品接口失败");
        }
    }

    @ApiOperation(value = "查询作品详情", notes = "查询作品详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "作品ID", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryByIdWorksInfo")
    @OperLog(operModul = "作品管理-查看作品",operType = "查询",operDesc = "查看作品详情")
    public ResponseResult queryByIdWorksInfo(String id){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.queryByIdWorksInfo(id));
        }catch (Exception ex) {
            logger.error("查询作品详情接口失败", ex);
            return ResultGenerator.genFailResult("查询作品详情接口失败");
        }
    }

    @ApiOperation(value = "删除作品", notes = "删除作品接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "作品ID", dataType = "String", paramType = "query")
    })
    @PostMapping("/deleteWorksInfo")
    @OperLog(operModul = "作品管理-删除作品",operType = "删除",operDesc = "删除作品")
    public ResponseResult deleteWorksInfo(@RequestParam(value = "id",defaultValue = "")String id){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.deleteWorksInfo(id));
        }catch (Exception ex) {
            logger.error("删除作品接口失败", ex);
            return ResultGenerator.genFailResult("删除作品接口失败");
        }
    }

    @ApiOperation(value = "根据用户查询当前未投稿的作品", notes = "根据用户查询当前未投稿的作品接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByCreaterIdWorks")
    public ResponseResult<List<WorksInfo>> queryByCreaterIdWorks(Integer userId){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.queryByCreaterIdWorks(userId));
        }catch (Exception ex) {
            logger.error("根据用户查询当前未投稿的作品接口失败", ex);
            return ResultGenerator.genFailResult("根据用户查询当前未投稿的作品接口失败");
        }
    }

    @ApiOperation(value = "代传作品", notes = "代传作品接口")
    @PostMapping("/generationUploadWorksInfo")
    @OperLog(operModul = "作品管理-代传作品",operType = "新增",operDesc = "代传作品")
    public ResponseResult generationUploadWorksInfo(@RequestBody WorksInfoVo worksInfoVo){
        try{
            return ResultGenerator.genSuccessResult(worksInfoService.generationUploadWorksInfo(worksInfoVo));
        }catch (Exception ex) {
            logger.error("代传作品接口失败", ex);
            return ResultGenerator.genFailResult("代传作品接口失败");
        }
    }
}
